﻿package com.tomvian.maths
{
	/**
	 * Range
	 * @author Thomas Vian
	 */
	public class Range
	{
		//--------------------------------------------------------------------------
		//
		//  Properties
		//
		//--------------------------------------------------------------------------
		
		public var max:Number;
		public var min:Number;
		public var range:Number;
		
		public var next:Range;
		
		//--------------------------------------------------------------------------
		//
		//  Constructor
		//
		//--------------------------------------------------------------------------
		
		public function Range(min:Number = 0, max:Number = 1)
		{
			this.max = max;
			this.min = min;
			this.range = max - min;
		}
		
		//--------------------------------------------------------------------------
		//
		//  Methods
		//
		//--------------------------------------------------------------------------
		
		public function getRandom():Number
		{
			return min + Math.random() * range;
		}
		
		public function limit(num:Number):Number
		{
			if(num <= min) return min;
			if(num >= max) return max;
			return num;
		}
		
		public function numInRange(num:Number):Boolean
		{
			return num >= min && num <= max;
		}
	}
}